home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / updates / update19.zoo / lib / diffs
Encoding:
Text File  |  1992-03-28  |  11.4 KB  |  551 lines

  1. *** 1.69    1992/03/22 21:57:30
  2. --- Changelo    1992/03/28 06:36:49
  3. ***************
  4. *** 2911,2913 ****
  5. --- 2911,2931 ----
  6.       merge diff for atof
  7.   
  8.   ---------------------------- Patchlevel 78 ---------------------------
  9. + signal.c, console.c: alexander lehmann
  10. +   fix for a bug where console i/o would get stuck when a interrupt
  11. +   was caught and it occured when the input buffer was not empty.
  12. + fread.c, fwrite.c: alexander lehmann
  13. +   I rewrote fread and fwrite to do CR/LF conversion when in text mode.
  14. +   Additionally I fixed a small bug in eof detection.
  15. +   ( this pertains to the example when you are fread'ing say 20 bytes
  16. +     from a file that contains 18 bytes: in the old coding
  17. +     you would first succeeed with a count of 18, and on subsequent
  18. +     freads you would get eof. In this coding, you get a count of 18
  19. +     and also eof flag:
  20. +     Well this was not really a bug, just when eof shows up. My ansiC
  21. +     doc is mum on this point) -- ++jrb
  22. + ---------------------------- Patchlevel 79 ---------------------------
  23. *** 1.54    1992/03/22 21:57:30
  24. --- PatchLev.h    1992/03/28 06:37:02
  25. ***************
  26. *** 1,5 ****
  27.   
  28. ! #define    PatchLevel "78"
  29.   
  30.   /*
  31.    *
  32. --- 1,5 ----
  33.   
  34. ! #define    PatchLevel "79"
  35.   
  36.   /*
  37.    *
  38. *** 1.9    1991/09/24 16:44:02
  39. --- console.c    1992/03/24 18:54:00
  40. ***************
  41. *** 36,43 ****
  42.   } k_buf;
  43.   
  44.   k_buf in_buf[NUMDEV];
  45. - #define IN_BUF(dev) (&in_buf[(dev) > 2 ? _console_dev : (dev)])
  46.   
  47.   /*
  48.    * what handle means:: 0-2: BIOS handle, 3: stdout, 4: stderr
  49.    */
  50. --- 36,46 ----
  51.   } k_buf;
  52.   
  53.   k_buf in_buf[NUMDEV];
  54.   
  55. + #define in_dev(dev) ((dev)>2 ? _console_dev : (dev))
  56. + #define IN_BUF(dev) (&in_buf[in_dev(dev)])
  57.   /*
  58.    * what handle means:: 0-2: BIOS handle, 3: stdout, 4: stderr
  59.    */
  60. ***************
  61. *** 44,49 ****
  62. --- 47,53 ----
  63.   static short LOOKUP __PROTO((short handle));
  64.   static long raw_in __PROTO((int dev));
  65.   static long raw_instat __PROTO((int dev));
  66. + void flush_key_buff __PROTO((int dev));
  67.   #if 0
  68.   static void raw_out __PROTO((int dev, int c));
  69.   #endif
  70. ***************
  71. *** 81,92 ****
  72.   raw_in(dev)
  73.   int dev;
  74.   {
  75. !     if (dev < 3)
  76. !         return Bconin(dev);
  77. !     else if (dev == 3)
  78. !         return Crawcin();
  79. !     else
  80. !         return Cauxin();
  81.   }
  82.   
  83.   #if 0
  84. --- 85,91 ----
  85.   raw_in(dev)
  86.   int dev;
  87.   {
  88. !     return Bconin(in_dev(dev));
  89.   }
  90.   
  91.   #if 0
  92. ***************
  93. *** 107,118 ****
  94.   raw_instat(dev)
  95.   int dev;
  96.   {
  97. !     if (dev < 3)
  98. !         return Bconstat(dev);
  99. !     else if (dev == 3)
  100. !         return Cconis();
  101. !     else
  102. !         return Cauxis();
  103.   }
  104.   
  105.   /*
  106. --- 106,112 ----
  107.   raw_instat(dev)
  108.   int dev;
  109.   {
  110. !     return Bconstat(in_dev(dev));
  111.   }
  112.   
  113.   /*
  114. ***************
  115. *** 165,208 ****
  116.   int handle;
  117.   int n;
  118.   {
  119. -     long c;
  120. -     short i, j, waiting = 0;
  121.       char ch;
  122. -     k_buf *p;
  123.       short dev;
  124.   
  125.       dev = LOOKUP(handle);
  126. -     p = IN_BUF(dev);
  127.   
  128. !     while (__check_signals && (raw_instat(dev) || waiting)) {
  129. !         c = raw_in(dev);
  130. !         if (!(__ttymode & RAW)) {
  131. !             ch = c & 0xff;
  132. !             if (ch == ('S'-'@')) {
  133. !                 waiting = 1;
  134. !             }
  135. !             else if (ch == ('Q'-'@')) {
  136. !                 waiting = 0;
  137. !             }
  138. !             else if (ch == __tchars[TC_INTRC]) {
  139. !                 p->head = p->tail;
  140. !                 raise(SIGINT);
  141. !             }
  142. !             else if (ch == __tchars[TC_QUITC]) {
  143. !                 p->head = p->tail;
  144. !                 raise(SIGQUIT);
  145. !             }
  146. !             else if (!waiting) {
  147. !                 i = p->head;
  148. !                 j = i + 1;
  149. !                 if (j >= KBUFSIZ) j = 0;
  150. !                 if (j != p->tail) {
  151. !                     p->buffer[i] = c;
  152. !                     p->head = j;
  153. !                 }
  154. !             }
  155. !         }
  156. !     }
  157.   /*    raw_out(dev, n); */
  158.       ch = n;
  159.       (void)Fwrite(handle, 1L, &ch);
  160. --- 159,171 ----
  161.   int handle;
  162.   int n;
  163.   {
  164.       char ch;
  165.       short dev;
  166.   
  167.       dev = LOOKUP(handle);
  168.   
  169. !     if (__check_signals)
  170. !         flush_key_buff(dev);
  171.   /*    raw_out(dev, n); */
  172.       ch = n;
  173.       (void)Fwrite(handle, 1L, &ch);
  174. ***************
  175. *** 255,257 ****
  176. --- 218,221 ----
  177.       }
  178.       }
  179.   }
  180. *** 1.11    1992/03/22 21:57:30
  181. --- fread.c    1992/03/24 18:54:21
  182. ***************
  183. *** 1,4 ****
  184. ! /* nothing like the origonal from
  185.    * from Dale Schumacher's dLibs
  186.    */
  187.   
  188. --- 1,4 ----
  189. ! /* nothing like the original from
  190.    * from Dale Schumacher's dLibs
  191.    */
  192.   
  193. ***************
  194. *** 10,17 ****
  195.   #include <string.h>
  196.   #include "lib.h"
  197.   
  198. ! size_t  fread(data, size, count, fp)
  199. !     register void *data;
  200.       size_t size;
  201.       size_t count;
  202.       register FILE *fp;
  203. --- 10,17 ----
  204.   #include <string.h>
  205.   #include "lib.h"
  206.   
  207. ! size_t    fread(_data, size, count, fp)
  208. !     void *_data;
  209.       size_t size;
  210.       size_t count;
  211.       register FILE *fp;
  212. ***************
  213. *** 19,24 ****
  214. --- 19,26 ----
  215.       register size_t n;
  216.       register long l, cnt;
  217.       register unsigned int f;
  218. +     char *data=_data;
  219. +     char *ptr;
  220.   
  221.       assert((data != NULL));
  222.       assert((size != 0));
  223. ***************
  224. *** 35,40 ****
  225. --- 37,43 ----
  226.           return 0;
  227.   #endif
  228.       assert((n <= (size_t)LONG_MAX));
  229. +     if( f&_IOBIN ) {
  230.       again:    
  231.       if((cnt = fp->_cnt) > 0)
  232.       {
  233. ***************
  234. *** 62,77 ****
  235.           }
  236.           else
  237.           { /* read in n bytes into data */
  238. !         if((cnt = _read(fp->_file, data, (unsigned long)n))<=0) {
  239.               fp->_flag |= ((cnt == 0) ? _IOEOF : _IOERR);
  240.               goto ret;
  241.           }
  242. !                 data+=cnt;
  243. !                 l+=cnt;
  244. !                 n-=cnt;
  245. !                 goto again;
  246.           }
  247.       }
  248.       ret:
  249.       return((l > 0) ? ((size_t)l / size) : 0);
  250.       }
  251. --- 65,133 ----
  252.           }
  253.           else
  254.           { /* read in n bytes into data */
  255. !         if((cnt = _read(fp->_file, data, (unsigned long)n)) != n)
  256. !         {   /* EOF or error */
  257. !             fp->_flag |= ((cnt >= 0) ? _IOEOF : _IOERR);
  258. !         }
  259. !         if( cnt>0 )
  260. !             l += cnt;
  261. !         }
  262. !     }
  263. !     } else {
  264. !     while( n>0 ) {
  265. !         if( (cnt=fp->_cnt)>0 ) {
  266. !         ptr=(char*)fp->_ptr;
  267. !         while( n>0 && cnt>0 ) {
  268. !             if( *ptr!='\r' ) {
  269. !             *data++=*ptr++;
  270. !             cnt--;
  271. !             n--;
  272. !             l++;
  273. !             } else {
  274. !             ptr++;
  275. !             cnt--;
  276. !             }
  277. !         }
  278. !         fp->_cnt=cnt;
  279. !         fp->_ptr=(unsigned char*)ptr;
  280. !         }
  281. !         if( n==0 ) break; /* done */
  282. !         /* wanna have n more bytes */
  283. !         if( n<fp->_bsiz ) {
  284. !         /* read in fp->_bsiz bytes into fp->_base and do it again */
  285. !         fp->_ptr = fp->_base;
  286. !         if((cnt = _read(fp->_file, fp->_base, (unsigned long)fp->_bsiz)) <= 0)
  287. !         {   /* EOF or error */
  288.               fp->_flag |= ((cnt == 0) ? _IOEOF : _IOERR);
  289.               goto ret;
  290.           }
  291. !         fp->_cnt = cnt;
  292. !         } else {
  293. !         /* read in n bytes into data */
  294. !         if((cnt = _read(fp->_file, data, (unsigned long)n)) != n)
  295. !         {   /* EOF or error */
  296. !             fp->_flag |= ((cnt >= 0) ? _IOEOF : _IOERR);
  297. !             /* if EOF but read bytes still convert CRLF */
  298. !             if( cnt<=0 ) goto ret;
  299. !         }
  300. !         ptr=data;
  301. !         while( cnt>0 ) {
  302. !             if( *ptr!='\r' ) {
  303. !             *data++=*ptr++;
  304. !             cnt--;
  305. !             n--;
  306. !             l++;
  307. !             } else {
  308. !             ptr++;
  309. !             cnt--;
  310. !             }
  311. !         }
  312. !         if( fp->_flag&_IOEOF )
  313. !             goto ret;
  314.           }
  315.       }
  316. +     }
  317.       ret:
  318.       return((l > 0) ? ((size_t)l / size) : 0);
  319.       }
  320. *** 1.10    1992/03/22 21:57:30
  321. --- fwrite.c    1992/03/24 18:54:27
  322. ***************
  323. *** 8,23 ****
  324.   #include <string.h>
  325.   #include "lib.h"
  326.   
  327. ! size_t  fwrite(data, size, count, fp)
  328. !     const register void *data;
  329. !     size_t size;
  330. !     size_t count;
  331. !     register FILE *fp;
  332. !     {
  333.       register size_t n, m;
  334.       register long l = 0;
  335.       long space;
  336.       unsigned int f = fp->_flag;
  337.   
  338.       if(f & _IORW)
  339.       {
  340. --- 8,28 ----
  341.   #include <string.h>
  342.   #include "lib.h"
  343.   
  344. ! size_t    fwrite(_data, size, count, fp)
  345. ! const void *_data;
  346. ! size_t size;
  347. ! size_t count;
  348. ! register FILE *fp;
  349. ! {
  350. !     const char *data=_data;
  351.       register size_t n, m;
  352.       register long l = 0;
  353.       long space;
  354.       unsigned int f = fp->_flag;
  355. +     const char *restart_buf;
  356. +     int have_nl;
  357. +     int wrote_cr;
  358. +     int line_flush;
  359.   
  360.       if(f & _IORW)
  361.       {
  362. ***************
  363. *** 34,69 ****
  364.       n =  count * size;
  365.       assert ( n <= (size_t)LONG_MAX);  /* otherwise impl will not work */
  366.   
  367. !     space = fp->_bsiz - fp->_cnt;
  368. !     while(n > 0)
  369. !     {
  370. !         m = (n > space)? space: n;
  371. !         bcopy(data, fp->_ptr, m);
  372. !         fp->_ptr += m;
  373. !         fp->_cnt += m;
  374. !         space -= m;
  375. !         if(space == 0)
  376. !         {
  377. !         if(fflush(fp))
  378.               return 0;
  379. !         space = fp->_bsiz;
  380. !         if(f & _IORW)
  381. !             fp->_flag |= _IOWRT; /* fflush resets this */
  382. !         }
  383. !         l += m;
  384. !         data = (char *)data + m;
  385. !         n -= m;
  386. !         if(n < space)
  387. !         continue;
  388. !         if((m = _write(fp->_file, data, (unsigned long)n))
  389. !            != (long)n)
  390. !         {
  391. !         fp->_flag |= _IOERR;
  392. !         return 0;
  393. !         }
  394. !         l += m;
  395. !         break;
  396.       }
  397. !     
  398.       return((l > 0) ? ((size_t)l / size) : 0);
  399. !     }
  400. --- 39,138 ----
  401.       n =  count * size;
  402.       assert ( n <= (size_t)LONG_MAX);  /* otherwise impl will not work */
  403.   
  404. !     if( f&_IOBIN ) {
  405. !       space = fp->_bsiz - fp->_cnt;
  406. !       while(n > 0)
  407. !       {
  408. !           m = (n > space)? space: n;
  409. !           bcopy(data, fp->_ptr, m);
  410. !           fp->_ptr += m;
  411. !           fp->_cnt += m;
  412. !           space -= m;
  413. !           if(space == 0)
  414. !           {
  415. !           if(fflush(fp))
  416. !               return 0;
  417. !           space = fp->_bsiz;
  418. !           if(f & _IORW)
  419. !               fp->_flag |= _IOWRT; /* fflush resets this */
  420. !           }
  421. !           l += m;
  422. !           data += m;
  423. !           n -= m;
  424. !           if(n < space)
  425. !           continue;
  426. !           if((m = _write(fp->_file, data, (unsigned long)n )) != (long)n)
  427. !           {
  428. !           fp->_flag |= _IOERR;
  429. !           return 0;
  430. !           }
  431. !           l += m;
  432. !           break;
  433. !       }
  434. !     } else {
  435. !       have_nl=1;
  436. !       wrote_cr=0;
  437. !       line_flush=0;
  438. !       /* this relies on having at least one byte buffer,
  439. !          otherwise we'll hang up when trying to write CRLF */
  440. !       while(n > 0)
  441. !       {
  442. !           space = fp->_bsiz - fp->_cnt;
  443. !           restart_buf=data;
  444. !           while( space>0 && n>0 ) {
  445. !         if( *data=='\n' ) {
  446. !           if( !wrote_cr ) {
  447. !             if( f&_IOLBF ) line_flush=1;
  448. !             *fp->_ptr++='\r';
  449. !             wrote_cr=1;
  450. !             have_nl=1;
  451. !           } else {
  452. !             *fp->_ptr++='\n';
  453. !             data++;
  454. !             wrote_cr=0;
  455. !             n--;
  456. !           }
  457. !         } else {
  458. !           *fp->_ptr++=*data++;
  459. !           n--;
  460. !         }
  461. !         space--;
  462. !         fp->_cnt++;
  463. !         l++;
  464. !           }
  465. !           if( space==0 ) {
  466. !         if( have_nl ) {
  467. !           if(fflush(fp))
  468. !               return 0;
  469. !           if(f & _IORW)
  470. !               fp->_flag |= _IOWRT; /* fflush resets this */
  471. !           have_nl=0;
  472. !         } else {
  473. !         /* this will probably happen in nonbuffered mode only:
  474. !            try to write as much data in one go as possible */
  475. !           fp->_cnt=0;
  476. !           fp->_ptr=fp->_base;
  477. !           while( n && *data!='\n' ) {
  478. !             n--;
  479. !             data++;
  480. !           }
  481. !           if( (m=_write(fp->_file, restart_buf, data-restart_buf ))
  482. !               != data-restart_buf ) {
  483. !             fp->_flag |= _IOERR;
  484.               return 0;
  485. !           }
  486. !           l+=m;
  487. !         }
  488. !           }
  489. !       }
  490. !       if( line_flush ) {
  491. !          if(fflush(fp))
  492. !          return 0;
  493. !          if(f & _IORW)
  494. !          fp->_flag |= _IOWRT; /* fflush resets this */
  495. !       }
  496.       }
  497.       return((l > 0) ? ((size_t)l / size) : 0);
  498. ! }
  499. *** 1.6    1991/07/23 22:06:28
  500. --- signal.c    1992/03/24 18:54:36
  501. ***************
  502. *** 15,21 ****
  503.   #include    <unistd.h>
  504.   
  505.   extern int __check_signals;        /* used in console i/o routines */
  506. ! #define    SIG_EXIT    10        /* exit code */
  507.   
  508.   struct sigarray_str {
  509.         __Sigfunc s_func;
  510. --- 15,21 ----
  511.   #include    <unistd.h>
  512.   
  513.   extern int __check_signals;        /* used in console i/o routines */
  514. ! #define SIG_EXIT    10        /* exit code */
  515.   
  516.   struct sigarray_str {
  517.         __Sigfunc s_func;
  518. ***************
  519. *** 40,49 ****
  520.       case SIGINT:
  521.       case SIGQUIT:
  522.           if (func != SIG_IGN)
  523. !             __check_signals += 1;
  524.           else
  525. !             __check_signals = (__check_signals == 1) ? 
  526. !                      0 : --__check_signals;
  527.       case SIGALRM:
  528.       case SIGABRT:
  529.           oldfunc = sig_array[sig].s_func;
  530. --- 40,49 ----
  531.       case SIGINT:
  532.       case SIGQUIT:
  533.           if (func != SIG_IGN)
  534. !             __check_signals |= (sig==SIGINT ? 1 : 2);
  535.           else
  536. !             __check_signals &= (sig==SIGINT ? ~1 : ~2);
  537. !         /* falltrough */
  538.       case SIGALRM:
  539.       case SIGABRT:
  540.           oldfunc = sig_array[sig].s_func;
  541.